library AmmoAPI requires LegacySystem

	globals
		integer array AmmoSystemRounds
		integer array AmmoSystemMagazines
		trigger AmmoAutoReloadTrigger
		trigger AmmoEmptyTrigger
	endglobals
	
	function RegisterAmmoEmptyListener takes unit u returns nothing
		call TriggerRegisterPlayerStateEvent(AmmoEmptyTrigger, GetOwningPlayer(u), PLAYER_STATE_RESOURCE_GOLD, EQUAL, 0.0)
	endfunction
	
	function RegisterAmmoAutoReloadListener takes unit u returns nothing
		call TriggerRegisterPlayerStateEvent(AmmoAutoReloadTrigger, GetOwningPlayer(u), PLAYER_STATE_RESOURCE_GOLD, EQUAL, 0.0)
	endfunction

	function AddPrimaryAmmo takes unit u, integer clips, integer rounds returns nothing
		local player p = GetOwningPlayer(u)
		local integer id = GetConvertedPlayerId(p)
		set AmmoSystemRounds[id] = AmmoSystemRounds[id] + rounds
		set AmmoSystemMagazines[id] = AmmoSystemMagazines[id] + clips
		call SetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD, AmmoSystemRounds[id])
		call SetPlayerState(p,PLAYER_STATE_RESOURCE_LUMBER, AmmoSystemMagazines[id])
		call ShiftMoveSpeed(u,-1.4*I2R(clips))
		set p = null
	endfunction
	
	function GetPrimaryAmmoMagazines takes player p returns integer 
		return AmmoSystemMagazines[GetConvertedPlayerId(p)]
	endfunction
	
	function GetPrimaryAmmoRounds takes player p returns integer 
		return AmmoSystemRounds[GetConvertedPlayerId(p)] 
	endfunction
	
	
endlibrary